/**
 *
 */
package com.angel.mocks.data.generator.dataGenerator;

import java.io.FileNotFoundException;
import java.io.InputStream;

import com.angel.common.helpers.FileHelper;
import com.angel.dao.generic.interfaces.GenericDAO;
import com.angel.data.generator.interfaces.DataGenerator;
import com.angel.data.generator.interfaces.impl.ImportFileDataGenerator;
import com.angel.io.descriptor.FileProcessorDescriptor;
import com.angel.io.processors.commands.impl.ExcelFileProcessorCommand;
import com.angel.io.processors.runners.imports.impl.ImportFileProcessorRunner;
import com.angel.io.separator.ColumnSeparator;
import com.angel.mocks.data.generator.daos.impl.AddressHibernateDAO;
import com.angel.mocks.data.generator.domainObject.Address;
import com.angel.mocks.data.generator.rowProcessorCommand.AddressRowProcessorCommand;

/**
 * @author William
 *
 */
public class AddressImportFileDataGenerator extends ImportFileDataGenerator {

	private static final long serialVersionUID = -4818134865121048542L;

	public AddressImportFileDataGenerator(){
		super();
	}

	public AddressImportFileDataGenerator(Integer[] pages){
		super(pages);
	}

	@SuppressWarnings("unchecked")
	public Class<? extends DataGenerator>[] getDependecesGenerators() {
		return (Class<? extends DataGenerator>[]) new Class<?>[]{};
	}

	@SuppressWarnings("unchecked")
	public GenericDAO getGenericDAO() {
		return new AddressHibernateDAO();
	}

	public Class<? extends Object> getDataGeneratorClass() {
		return Address.class;
	}

	@Override
	public ImportFileProcessorRunner prepareImportFileProcessorRunner() {
		FileProcessorDescriptor descriptor = new FileProcessorDescriptor("USERs File", ColumnSeparator.COMMA);
		ImportFileProcessorRunner runner = new ImportFileProcessorRunner(descriptor,new ExcelFileProcessorCommand(), new AddressRowProcessorCommand());
		return runner;
	}

	@Override
	public InputStream prepareInputStream() {
		try {
			//TODO Add an exception when the source path is an invalid one.
			return findInputStreamFor("/target/test-classes/address.xls");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static InputStream findInputStreamFor(String fullPathFile) throws FileNotFoundException{
		String classPath = System.getProperty("user.dir") + fullPathFile;
		return FileHelper.findInputStreamInPath(classPath);
	}
}
